package com.lagou.homework4.no1;

import java.util.List;

/**
 * 修改学生信息
 */
public class UpdateStudent {
    public static List update(List list, Student stu){
        int result= 0;//记录修改结果是否成功
        for(int i=0;i<list.size();i++){
            Student student = (Student) list.get(i);
            if(student.getId()==stu.getId()){//判断要修改的学生学号是否存在
                if(stu.getName()!=null&&!student.getName().equals(stu.getName())){
                    student.setName(stu.getName());
                }
                if(stu.getAge()!=0&&stu.getAge()!=student.getAge()){
                    student.setAge(stu.getAge());
                }
                result++;
            }
        }
        if(result==0){
//            System.out.println("您输入的学号信息不存在！");
            try {
                throw new StunoException("您输入的学号信息不存在！");
            }catch (StunoException e){
                e.printStackTrace();
            }
        }
        return list;
    }
}
